//
//  ZZSearchUserCell.m
//  Qzone
//
//  Created by zhangxy on 2018/7/5.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "ZZSearchUserCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@implementation ZZSearchUserCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _imgAvatar.layer.cornerRadius = 22.0f;
    _imgAvatar.layer.masksToBounds = YES;
    
    
    [_labName setFont:FontFiftent];
    [_labName setTextColor:UIColorFromRGB(TextSizeOneColor)];
    
    [_btnLevel.titleLabel setFont:ListElevenFont];
    _btnLevel.layer.cornerRadius = 4.0f;
    _btnLevel.layer.masksToBounds = YES;
    _btnLevel.layer.borderWidth = 1.0f;
    _btnLevel.layer.borderColor = UIColorFromRGB(BorderLineColor).CGColor;
    [_btnLevel setTitleColor:UIColorFromRGB(TextSizeOneColor) forState:0];
    [_btnLevel setImage:[UIImage imageNamed:@"btn_collect"] forState:0];
}

-(void)dataToView:(User *) user{
    [_labName setText:convertToString(user.user_name)];
    [_imgAvatar sd_setImageWithURL:[NSURL URLWithString:convertToString(user.user_avatar)]];
    [_btnLevel setTitle:convertToString(user.user_gold) forState:0];
    
    [self autoWidthOfLabel:_labName with:21];
    
    CGRect f = _btnLevel.frame;
    f.origin.x = CGRectGetMaxX(_labName.frame) + 5;
    _btnLevel.frame = f;
}


/**
 计算Label高度
 
 @param label 要计算的label，设置了值
 @param width label的最大宽度
 */
- (CGSize )autoWidthOfLabel:(UILabel *)label with:(CGFloat )height{
    //Calculate the expected size based on the font and linebreak mode of your label
    // FLT_MAX here simply means no constraint in height
    CGSize maximumLabelSize = CGSizeMake(FLT_MAX, height);
    
    CGSize expectedLabelSize = [label sizeThatFits:maximumLabelSize];
    
    //adjust the label the the new height.
    CGRect newFrame = label.frame;
    newFrame.size.width = expectedLabelSize.width;
    label.frame = newFrame;
    [label updateConstraintsIfNeeded];
    
    return expectedLabelSize;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
